
capture log close
log using $log/AED_analysis_09_mobility_patterns, text replace

/* ------------------------------------------------------------------------------------ */
/* --- Estimation Results Table A.11 -------------------------------------------------- */
/* ------------------------------------------------------------------------------------ */ 


clear
clear matrix
clear mata
set maxvar 10000
set matsize 2000
set more off

set trace off
   
#d;
global xvars " vac_rate aloq   
				share_agriculture_avg share_industry_avg share_service_avg wanderungen_avg bip_avg 
				iza_alter_kat1 iza_alter_kat2 iza_alter_kat3 iza_alter_kat4 iza_sex iza_famstd
				i.iza_kind i.iza_abschluss_kat i.iza_ausb_kat
				iza_last_daily_income i.iza_beruf_kat
				iza_ende_last iza_vztz_last iza_zeit_la
				iza_sv_tminus1 iza_sv_tminus2 iza_sv_tminus3
				iza_lnwage_tminus1 iza_lnwage_tminus2 iza_lnwage_tminus3 
				i.year i.entry_m";
				#d cr
				

		use $data/data_est_border, clear
		
	
	
	keep if eintritt<=200805 & eintritt>=200706
	
	
	#d;
		egen month_sv1_12 = rsum(sv_tplus_1 sv_tplus_2 sv_tplus_3 sv_tplus_4 sv_tplus_5 sv_tplus_6 sv_tplus_7 sv_tplus_8 sv_tplus_9 sv_tplus_10 
		sv_tplus_11 sv_tplus_12)
		;
	
		#d cr

	
	replace iza_umzug12 = 0 if month_sv1_12==0
	
	#d;
	global outc "
	 iza_umzug12
	 umzugskosten_12
	 fahrkosten_12
	 ";
	#d cr

	
	bys iza_id: gen insample = 1 if _n==1

	
	foreach var in $outc {
		qui reg `var' log_intensity_alt $xvars pair_* [pw=1/fweight_reg], cluster(ba)
		matrix b=e(b)'
		matrix n=e(N)
		matrix v=e(V)
		matrix se=vecdiag(cholesky(diag(vecdiag(v[1..1,1..1]))))'
		qui sum `var' if e(sample)==1 & insample==1
		matrix m = r(mean)
		scalar r = 100*(b[1,1]/m)
		
		count if e(sample)==1 & insample==1
		matrix n=e(N)
		matrix d_`var'=b[1..1,1..1],se,r
		
		
		
	}
	


matrix d = d_iza_umzug12\d_umzugskosten_12\d_fahrkosten_12




matrix rownames d = "Relocation" "Relocation assistance" "Commuting assistance"


matrix colnames d = "Coef" "SE" "%-effect" 
mat list d


log close
